package com.ccc.demo1;

import org.apache.spark.graphx.EdgeTriplet;
import scala.Tuple2;
import scala.collection.Iterator;
import scala.collection.JavaConversions;
import scala.runtime.AbstractFunction1;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

//发消息方法
public class MySendMsg extends AbstractFunction1<EdgeTriplet<String, String>, Iterator<Tuple2<Object, String>>> implements
        Serializable {
    @Override
    public Iterator<Tuple2<Object, String>> apply(EdgeTriplet<String, String> triplet) {
        List<Tuple2<Object, String>> list = new ArrayList<>();

//        triplet.srcId();
//        triplet.dstId();
//        triplet.attr();  // 权重
//        triplet.srcAttr(); // 起点属性
//        triplet.dstAttr(); // 终点属性


        list.add(new Tuple2<>(triplet.srcId(), triplet.dstAttr()));
        list.add(new Tuple2<>(triplet.dstId(), triplet.srcAttr()));
        return JavaConversions.asScalaIterator(list.iterator());
    }
}
